package com.imay.live.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.imay.base.activity.BaseActivity;
import com.imay.live.cache.UserInfoCache;
import com.imay.live.fragment.ProfileFragment;
import com.imay.live.helper.RepostHelper;
import com.imay.live.model.MenuItemModel;
import com.imay.live.view.dialog.ChoiseDialogFragment;
import com.imay.live.R;
import com.umeng.socialize.UMShareAPI;

import java.util.ArrayList;
import java.util.List;

/**
 * create by nick
 * 个人信息界面
 */
public class ProfileActivity extends BaseActivity  {

    private static final String UID_TAG = "uid";
    private static final String FROM_TYPE = "from_type";
    private static final int MENU_ACTION_DYNAMICS_REPORT = 1;
    public static final int FROM_TYPE_SHORT_LIVE = 3;
    private static final int TAG1 =2 ;
    private long uid;

    /**
     * @param context
     * @param uid  uid 不传，默认加载当前用户信息
     */
    public static void start(Context context, long uid) {
        Intent starter = new Intent(context, ProfileActivity.class);
        starter.putExtra(UID_TAG,uid);
        context.startActivity(starter);
    }
    /**
     * @param context
     * @param uid  uid 不传，默认加载当前用户信息
     * @param fromType  fromType 跳转来源
     */
    public static void start(Context context, long uid,int fromType) {
        Intent starter = new Intent(context, ProfileActivity.class);
        starter.putExtra(UID_TAG,uid);
        starter.putExtra(FROM_TYPE,fromType);
        context.startActivity(starter);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_profile;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        uid = getIntent().getLongExtra(UID_TAG,0);
        int fromType = getIntent().getIntExtra(FROM_TYPE,0);
        setTitle(getString(R.string.str_bottom_me));
        ProfileFragment fragment = ProfileFragment.newInstance(uid,fromType);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fl_container, fragment);
        fragmentTransaction.commitAllowingStateLoss();
        if (!isSelf()){
            final List<MenuItemModel> strings = new ArrayList<>();
            strings.add(new MenuItemModel(MENU_ACTION_DYNAMICS_REPORT, R.string.str_dynamics_report));

            final RepostHelper repostHelper = RepostHelper.getInstance();
            getTitleBar().setRightImageResource(R.mipmap.btn_00t_more);
            getTitleBar().setRightImageOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showRepostDailog(strings, repostHelper);

                }
            });
        }
    }

    private void showRepostDailog(List<MenuItemModel> strings, final RepostHelper repostHelper) {
        ChoiseDialogFragment.show(getSupportFragmentManager(), strings, TAG1, new ChoiseDialogFragment.OnItemClickListener() {
            @Override
            public void itemClick(int tagCallBack, int position, MenuItemModel str) {
                repostHelper.reportUser(getSupportFragmentManager(),ProfileActivity.this,uid,true);
            }
        });
    }

    private boolean isSelf(){
        if ( UserInfoCache.getUserInfo()!=null){
            return UserInfoCache.getUserInfo().getUser().getUid()==uid;
        }
        return false;

    }
}
